package com.baseframe.mybatis.launch;

import com.baseframe.launch.scan.ImportLauncher;
import com.baseframe.launch.service.BaseLauncherService;
import org.springframework.boot.builder.SpringApplicationBuilder;

import java.util.Properties;

@ImportLauncher
public class BaseMyBatisPlusLaunchServiceImpl implements BaseLauncherService {
    private static final String MAPPER_LOCATIONS = "classpath:com/baseframe/**/mapper/*Mapper.xml";
    private static final String TYPE_ALIASES_PACKAGE = "com.baseframe.**.entity";
    private static final String LOGIC_DELETE_FIELD = "isDeleted";
    private static final String SQL_LOG_INTERCEPTOR = "sqlLogInterceptor";
    @Override
    public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
        Properties properties = System.getProperties();
        //设置mybatis-plus的扫包
        properties.setProperty("mybatis-plus.mapper-locations",MAPPER_LOCATIONS);
        properties.setProperty("mybatis-plus.typeAliasesPackage",TYPE_ALIASES_PACKAGE);
        properties.setProperty("mybatis-plus.global-config.db-config.logic-delete-field",LOGIC_DELETE_FIELD);
        //设置日志拦截器
        properties.setProperty("spring.datasource.dynamic.druid.proxy-filters[0]", SQL_LOG_INTERCEPTOR);

        System.out.printf("mybatis-plus.mapper-locations:%s%n",MAPPER_LOCATIONS);
        System.out.printf("mybatis-plus.typeAliasesPackage:%s%n",TYPE_ALIASES_PACKAGE);
        System.out.printf("mybatis-plus.global-config.db-config.logic-delete-field:%s%n",LOGIC_DELETE_FIELD);
        System.out.printf("spring.datasource.dynamic.druid.proxy-filters:%s%n", SQL_LOG_INTERCEPTOR);


    }

    @Override
    public int getOrder() {
        return 1;
    }
}
